package com.laosg.spring.small.core02.factory.support;

import com.laosg.spring.small.core02.exception.BeansException;
import com.laosg.spring.small.core02.factory.config.BeanDefinition;

import java.util.HashMap;
import java.util.Map;

/**
 * <p>description: some thing </p>
 *
 * @author kevin
 * @date 8/18/21
 */
public class DefaultListableBeanFactory extends AbstractAutowireCapableBeanFactory implements BeanDefinitionRegistry{
    private Map<String,BeanDefinition> beanDefinitionMap =new HashMap<>();


    @Override
    protected BeanDefinition getBeanDefinition(String beanName) throws BeansException {
        BeanDefinition beanDefinition = beanDefinitionMap.get(beanName);
        if (beanDefinition == null) {
            throw new BeansException("No bean named "+ beanName +"is defined");
        }

        return beanDefinition;
    }

    @Override
    public void registryBeanDefinition(String beanName, BeanDefinition beanDefinition) {
        beanDefinitionMap.put(beanName, beanDefinition);
    }
}
